package edu.mobbuzz.facade;

import edu.mobbuzz.bean.Category;
import edu.mobbuzz.storage.CategoryRecordStore;
import java.util.Vector;

public class CategoryFacade {
    private CategoryRecordStore categoryRS;
    private Vector categoryArr;
    
    public CategoryRecordStore getCategoryRS() {
        if(categoryRS==null){
            categoryRS = new CategoryRecordStore();
        }
        return categoryRS;
    }

    public void setCategoryRS(CategoryRecordStore categoryRS) {
        this.categoryRS = categoryRS;
    }

    public Category getCategoryById (int recId){
        return getCategoryRS().getCategoryById(recId);
    }
	
	 public Vector displayCategoryList() {

        categoryArr = new Vector();
        if(getCategoryRS().getNbCategory()==0){
            Category category1 = new Category();
            category1.setLabel("Music");
            category1.setDescription("");
            Category category2 = new Category();
            category2.setLabel("Movie");
            category2.setDescription("");
            Category category3 = new Category();
            category3.setLabel("Campus");
            category3.setDescription("");


            getCategoryRS().addCategory(category1);
            getCategoryRS().addCategory(category2);
            getCategoryRS().addCategory(category3);
        }
        if(getCategoryRS().readRSCategory()){
            for(int i=0;i<getCategoryRS().getNbCategory();i++){
                categoryArr.addElement(new Category(getCategoryRS().categoryArr[i].getRecId(),
                                                    getCategoryRS().categoryArr[i].getLabel(),
                                                    getCategoryRS().categoryArr[i].getDescription()));

            }
        }else{
            System.out.println("RS Category Gagal dibuka");
        }


        return categoryArr;
    }


	public void addCategory(Category category) {
        getCategoryRS().addCategory(category);
	}

    public void updateCategory(int index, Category category) {
        getCategoryRS().updateCategory(index, category);
	}

    public void deleteCategory(int index) {
        getCategoryRS().deleteCategory(index);
	}

    public void closeCategoryRS() {
        getCategoryRS().closeRecStore();
	}
	 
}
 
